// with polyfills
import 'core-js/stable';
import 'regenerator-runtime/runtime';

import { createApp } from 'vue';
import Antd from 'ant-design-vue';
import 'ant-design-vue/dist/antd.css';
// @ts-ignore
import App from "./App.vue";
import { setupRouter } from './router';
import { setupStore } from '@/store';
import { setupI18n } from '@/locales';
import 'ant-design-vue/dist/antd.css';
import { setupAntd, setupAssets, setupGlobalMethods, setupCustomComponents } from '@/plugins';
import AntDesignVue from 'ant-design-vue';
import 'ant-design-vue/dist/antd.css';

import * as Icons from '@ant-design/icons-vue';
import type { Component } from 'vue';
import 'ant-design-vue/dist/antd.css'; // 引入样式文件


if (process.env.NODE_ENV === 'production') {
  const { mockXHR } = require('./mock');
  mockXHR();
}

const app = createApp(App);
function setupPlugins () {
  // 注册全局常用的ant-design-vue组件
  app.use(AntDesignVue);
  setupAntd(app);
  // 引入静态资源
  setupAssets();
  // 注册全局自定义组件,如：<svg-icon />
  setupCustomComponents(app);
  // 注册全局方法，如：app.config.globalProperties.$message = message
  setupGlobalMethods(app);
}

async function setupApp () {
  // 挂载vuex状态管理
  setupStore(app);
  // Multilingual configuration
  // Asynchronous case: language files may be obtained from the server side
  await setupI18n(app);
  // 挂载路由
  await setupRouter(app);
  app.use(Antd);
  const IconData: Record<string, Component> = Icons;
  console.log('IconData', IconData);
  Object.keys(IconData).forEach((key: string) => {
    app.component(key, IconData[key]);
  });
  app.mount('#app');
}

setupPlugins();

setupApp();
